package com.ruoyi.project.purchase.controller;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.purchase.domain.Purch_drug;
import com.ruoyi.project.purchase.domain.Purchase;
import com.ruoyi.project.purchase.service.PurchaseService;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/supchase/index")
public class PurchaseController extends BaseController {

    @Autowired
    private PurchaseService purchaseService;

    @RequestMapping("/findSupplier")
    public AjaxResult findSupplier(){
        return AjaxResult.success(purchaseService.findAllSup());
    }

    @RequestMapping("/findAllPurchase")
    public TableDataInfo findAllPurchase(Purchase purchase){
        List<Purchase> allPur = purchaseService.findAllPur(purchase);
        return getDataTable(allPur);
    }

    @GetMapping("/findOnePurchase/{purOrderId}")
    public AjaxResult findOnePurchase(@PathVariable String purOrderId){
        System.out.println(purOrderId);

        if (purOrderId.equals("0")){
            Purchase purchase = purchaseService.returnNewPur();
            return AjaxResult.success(purchase);
        }else {
            Purchase onePur = purchaseService.findOnePur(purOrderId);
            return AjaxResult.success(onePur);
        }
    }
    @RequestMapping("/putCheck/{purOrderId}")
    public AjaxResult putCheck(@PathVariable String purOrderId){
        int i = purchaseService.changePurVerify(purOrderId);
        return toAjax(i);
    }

    @DeleteMapping("/remove/{purOrderId}")
    public AjaxResult removePur(@PathVariable String[] purOrderId){
        int i = purchaseService.deletePurchase(purOrderId);
        return toAjax(i);
    }
    @DeleteMapping("/RuChange/{purOrderId}")
    public AjaxResult RuChange(@PathVariable String[] purOrderId){
        int i = purchaseService.ReChangePurVerify(purOrderId);
        return toAjax(i);
    }
    @GetMapping("/changeOK/{purOrderId}")
    public AjaxResult changeOK(@PathVariable String[] purOrderId){
        int i = purchaseService.changeOk(purOrderId);
        return toAjax(i);
    }
    @GetMapping("/changeNo/{purOrderId}")
    public AjaxResult changeNo(@PathVariable String[] purOrderId){
        int i = purchaseService.changeNo(purOrderId);
        return toAjax(i);
    }
}
